package com.suyang.syt.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.suyang.syt.dao.interfaces.GroupDao;
import com.suyang.syt.model.Group;

@Repository
public class GroupDaoImpl extends BaseDaoImpl<Group> implements GroupDao {

	@Override
	public Group loadByTtcid(long ttcid) {
		List<Group> list = this.list(" from Group where ttcid=? ", ttcid);
		if (list != null && list.size() == 1) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public long countByTtcid(long ttcid) {
		String hql = " select count(*) from Group where ttcid=? ";
		return (Long) this.queryByHql(hql, ttcid);
	}

	@Override
	public void deletes(String ids) {
		this.executeByHql("delete Group where id in(" + ids + ")");
	}

	@Override
	public void disableGroup(String groupIds) {
		this.executeByHql("update Group set enabled = -1 where id in(" + groupIds + ")");
	}

	@Override
	public void enableGroup(String groupIds) {
		this.executeByHql("update Group set enabled = 1 where id in(" + groupIds + ")");
	}

	@Override
	public List<Group> findByIds(String ids) {
		return this.list("from Group  where id in(" + ids + ")");
	}

	@Override
	public List<Group> listGroup() {
		return this.list("from Group where id != 1");
	}

	@Override
	public long countName(String name) {
		String hql = " select count(*) from Group g where g.name=? ";
		return (Long) this.queryByHql(hql, name);
	}
}